public  class  NewCoder  {
    public ListNode reverseBetween (ListNode head, int m, int n) {
        ListNode fast = head, slow = head, temp;
        for(int i = 0; i < n - 1; i++)
            fast = fast.next;
        for(int i = 0; i < m - 2; i++)
            slow = slow.next;
        if(m == n)
            return head;
        if(m != 1){
            temp = slow;
            slow = slow.next;
            temp.next = fast;
        } else
            head = fast;
        while(slow != fast){
            temp = slow;
            slow = slow.next;
            temp.next = fast.next;
            fast.next = temp;
        }
        return head;
    }
}
